package com.diaohw.module.system.obj.tables;

import com.diaohw.platform.framework.db.flex.obj.tables.BaseTableDef;
import com.mybatisflex.core.query.QueryColumn;

import java.io.Serial;

/**
 * 用户 表定义层。
 *
 * @author D-Hw
 * @since 2024-11-15 18:22:15
 */
public class AccountDef extends BaseTableDef {

    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 用户
     */
    public static final AccountDef ACCOUNT = new AccountDef();

    /**
     * 加密盐值
     */
    public final QueryColumn SALT = new QueryColumn(this, "SALT");

    /**
     * 邮箱
     */
    public final QueryColumn EMAIL = new QueryColumn(this, "EMAIL");

    /**
     * 状态;状态，0：禁用，1：启用，2：锁定
     */
    public final QueryColumn STATE = new QueryColumn(this, "STATE");

    /**
     * 头像;对应文件服务的ID
     */
    public final QueryColumn AVATAR = new QueryColumn(this, "AVATAR");

    /**
     * 备注
     */
    public final QueryColumn REMARK = new QueryColumn(this, "REMARK");

    /**
     * 联系方式
     */
    public final QueryColumn CONTACT = new QueryColumn(this, "CONTACT");

    /**
     * 昵称
     */
    public final QueryColumn NICKNAME = new QueryColumn(this, "NICKNAME");

    /**
     * 密码
     */
    public final QueryColumn PASSWORD = new QueryColumn(this, "PASSWORD");

    /**
     * 账号
     */
    public final QueryColumn USERNAME = new QueryColumn(this, "USERNAME");

    /**
     * 部门ID
     */
    public final QueryColumn DEPARTMENT_ID = new QueryColumn(this, "DEPARTMENT_ID");


    /**
     * 默认字段，不包含逻辑删除或者 large 等字段。
     */
    public final QueryColumn[] DEFAULT_COLUMNS = new QueryColumn[]{USERNAME, PASSWORD, SALT, NICKNAME, EMAIL, CONTACT, AVATAR, REMARK, STATE, DEPARTMENT_ID};

    public AccountDef() {
        super("", "ACCOUNT");
    }

    private AccountDef(String schema, String name, String alisa) {
        super(schema, name, alisa);
    }

    public AccountDef as(String alias) {
        String key = getNameWithSchema() + "." + alias;
        return getCache(key, k -> new AccountDef("", "ACCOUNT", alias));
    }

}
